<?php
/*
 * Created on Dec 21, 2009
 *
 * User profile
 * 
 */

$id=$_GET[page_profile];

$usee=getUserById($id);
if ($usee){

	$useegame=getGameByGameid($usee['lastplayedgameid']);
	$useecreatedgame=getGameByGameid($usee['lastcreatedgameid']);

	if ($usee['id']==$user['id']){
		echo "<a href='$page_editprofile' target=_self>Edit profile</a>";
		$me=" [me]";
	} else {
		$me=null;
	}
	echo "<h2>";
	echo $usee['nickname'].$me; 
	echo "</h2>";

?>
<table class=smalltable>
<tr>
<td class='tdkey status'>
	Status
</td>
<td><?php if(getUserStatus($usee)){
	echo "<table><tr><td>";
	echo "<div class=online></div>";
	echo "</td><td>Online</td></tr></table>";
} else {
	echo "<table><tr><td>";
	echo "<div class=offline></div>";
	echo "</td><td>Offline</td></tr></table>";
}
 ?></td>
</tr>

<tr>
<td class=tdkey>Login name</td>
<td><?php echo $usee['loginname']; ?></td>
</tr>

<tr>
<td class=tdkey>Score</td>
<td><?php echo $usee['score']; ?></td>
</tr>

<tr>
<td class=tdkey>Moves history</td>
<td><table class=bigtable>
	<tr class=heading><td>Difficulty</td><td>Correct moves</td><td>Incorrect moves</td></tr>
<?php 
	$movehist=getMovehistUser($usee); 
	foreach($movehist as $key=>$value){
		$diff=$difficulty[$key];
		$correct=$value[0];
		$incorrect=$value[1];
		echo "<tr><td>$diff</td><td>$correct</td><td>$incorrect</td></tr>";
	}
	?>
</table></td>
</tr>

<?php if($useecreatedgame){ ?>
<tr>
<td class=tdkey>Last created game </td>
<td><a href='<?php echo "$game_join&gameid=".$useecreatedgame['gameid']; ?>' target=_self><?php echo $useecreatedgame['gamename']; ?></a></td>
</tr>
<?php } ?>

<?php if($useegame){ ?>
<tr>
<td class=tdkey>Currently playing in room </td>
<td><a href='<?php echo "$game_join&gameid=".$useegame['gameid']; ?>' target=_self><?php echo $useegame['gamename']; ?></a></td>
</tr>
<?php } ?>



</table>
<?php } ?>
<div class='center'>
<?php
if (isset($usee['chatlogid']) && $usee['chatlogid']){
	printChat("user");
	printChatInitializeScript("user",$usee['chatlogid'],urlencode($user['nickname']));
}
?>
</div>